package com.slipper.codeless.resolve.query;

import com.slipper.util.Tool;

import java.util.ArrayList;
import java.util.List;

public class Query {
    private boolean local = true; // 是否本地
    private String datasourceId; // 数据源id
    private String tableName; // 查询的表名
    private List<LeftJoinQuery> leftJoinQueryList = new ArrayList<>(); // 左连接查询
    private List<QueryField> queryFieldList = new ArrayList<>(); // 查询返回的结果字段
    private List<List<Condition>> conditionList = new ArrayList<>(); // 查询条件信息
    private List<List<Condition>> orConditionList = new ArrayList<>(); // or查询字段信息
    private List<SortField> sortFieldList = new ArrayList<>(); // 排序字段信息

    public boolean isLocal() {
        return local;
    }

    public void setLocal(boolean local) {
        this.local = local;
    }

    public String getDatasourceId() {
        return datasourceId;
    }

    public void setDatasourceId(String datasourceId) {
        this.datasourceId = datasourceId;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public List<LeftJoinQuery> getLeftJoinQueryList() {
        return leftJoinQueryList;
    }

    public void setLeftJoinQueryList(List<LeftJoinQuery> leftJoinQueryList) {
        this.leftJoinQueryList = leftJoinQueryList;
    }

    public List<List<Condition>> getConditionList() {
        return conditionList;
    }

    public void setConditionList(List<List<Condition>> conditionList) {
        this.conditionList = conditionList;
    }

    public List<List<Condition>> getOrConditionList() {
        return orConditionList;
    }

    public void setOrConditionList(List<List<Condition>> orConditionList) {
        this.orConditionList = orConditionList;
    }

    public List<QueryField> getQueryFieldList() {
        return queryFieldList;
    }

    public void setQueryFieldList(List<QueryField> queryFieldList) {
        this.queryFieldList = queryFieldList;
    }

    public List<SortField> getSortFieldList() {
        return sortFieldList;
    }

    public void setSortFieldList(List<SortField> sortFieldList) {
        this.sortFieldList = sortFieldList;
    }

    public void addLeftJoinQuery(LeftJoinQuery leftJoinQuery) {
        this.leftJoinQueryList.add(leftJoinQuery);
    }

    public void addSortField(String tableAlias, String fieldName, String ordinalMode, Integer ordinal) {
        if (Tool.isBlank(fieldName)) return;
        this.sortFieldList.add(new SortField(tableAlias, fieldName, ordinalMode, ordinal));
    }

    public void addSortField(String fieldName, String ordinalMode, Integer ordinal) {
        if (Tool.isBlank(fieldName)) return;
        this.sortFieldList.add(new SortField(fieldName, ordinalMode, ordinal));
    }

    public void addCondition(List<Condition> condition) {
        if (!condition.isEmpty()) {
            this.conditionList.add(condition);
        }
    }

    public void addOrCondition(List<Condition> conditionList) {
        this.orConditionList.add(conditionList);
    }

    public void addQueryField(QueryField queryField) {
        this.queryFieldList.add(queryField);
    }
}